/////////////////////////////////////////////////////////////////////
//  File Name               : s_system_d2math_matrix.inl
//  Created                 : 20 3 2012
//  File path               : SLibF\system\Include
//  Author                  : Alexandru Motriuc
//  Platform Independent    : 0%
//  Library                 : 
//
/////////////////////////////////////////////////////////////////////
//	Purpose:
//      
//
/////////////////////////////////////////////////////////////////////
//
//  Modification History:
//      
/////////////////////////////////////////////////////////////////////

//-------------------------------------------------------------------
inline d2Matrix::d2Matrix()
{
}

//-------------------------------------------------------------------
inline d2Matrix::d2Matrix( d2Float v )
{
	_11 = _22 = _33 = v;
  
	_12 = _13 = 
	_21 = _23 =
	_31 = _32 = 0.0f;
}

//-------------------------------------------------------------------
inline void d2Matrix::Mul( d2Matrix& r, const d2Matrix& a, const d2Matrix& b )
{
	__S_ASSERT( &r != &a );
	__S_ASSERT( &r != &b );

	r._11 = a._11 * b._11 + a._12 * b._21 + a._13 * b._31;
	r._12 = a._11 * b._12 + a._12 * b._22 + a._13 * b._32;
	r._13 = a._11 * b._13 + a._12 * b._23 + a._13 * b._33;

	r._21 = a._21 * b._11 + a._22 * b._21 + a._23 * b._31;
	r._22 = a._21 * b._12 + a._22 * b._22 + a._23 * b._32;
	r._23 = a._21 * b._13 + a._22 * b._23 + a._23 * b._33;

	r._31 = a._31 * b._11 + a._32 * b._21 + a._33 * b._31;
	r._32 = a._31 * b._12 + a._32 * b._22 + a._33 * b._32;
	r._33 = a._31 * b._13 + a._32 * b._23 + a._33 * b._33;  
}

//-------------------------------------------------------------------
inline void d2Matrix::SetRotate( d2Float a )
{
	_22 = _11 = FMath::Cos( a );
	_21 = FMath::Sin( a );
	_12 = - _21;

	_33 = 1.0f;
	_31 = _32 = _23 = _13 = 0.0f;
}

//-------------------------------------------------------------------
inline void d2Matrix::SetScale( d2Float x, d2Float y )
{
	_11 = x;
	_22 = y;
	_33 = 1.0f;

	_12 = _13 = 
	_21 = _23 = 
	_31 = _32 = 0.0f;
}

//-------------------------------------------------------------------
inline void d2Matrix::SetTranslation( const d2Vector& v )
{
	_11 = _22 = _33= 1.0f;

	_12 = _13 = 
	_21 = _23 = 0.0f;

	_31 = v.x;
	_32 = v.y;
}

//-------------------------------------------------------------------
inline void d2Matrix::SetTranslationX( d2Float x )
{
	SetTranslation( d2Vector( x, 0.0f ) );
}

//-------------------------------------------------------------------
inline void d2Matrix::SetTranslationY( d2Float y )
{
	SetTranslation( d2Vector( 0.0f, y ) );
}

//-------------------------------------------------------------------
inline void d2Matrix::Transpose( d2Matrix& r )
{
	d2Float temp;

	temp  = r._12;
	r._12 = r._21;
	r._21 = temp;

	temp  = r._13;
	r._13 = r._31;
	r._31 = temp;


	temp  = r._23;
	r._23 = r._32;
	r._32 = temp;
}

//-------------------------------------------------------------------
inline void d2Matrix::Transpose()
{
	Transpose( *this );
}
